package com.quick.develop.flowable.controller.manage;

import com.quick.develop.framework.common.page.R;
import com.quick.develop.flowable.application.IBpmManageApplication;
import com.quick.develop.flowable.domain.manage.BpmManageReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author junyuan.liu
 * @description:
 * @date 2022/9/14 13:37
 */
@Api(tags = "流程管理后台 - 流程管理")
@RestController
@RequestMapping("/manage")
public class BpmManageController {
    @Resource
    IBpmManageApplication bpmManageApplication;
    
    @DeleteMapping("/delete-instances")
    @ApiOperation(value = "删除流程，联级删除所有相关流程信息")
    public R<?> deleteInstances(@RequestBody BpmManageReqVO reqVO) {
        bpmManageApplication.deleteInstances(reqVO);
        return R.ok();
    }

    @GetMapping("/get-run-tasks/{processInstanceId}")
    @ApiOperation(value = "获取正在运行的任务")
    public R<?> getRunTasks(@PathVariable("processInstanceId") String id ) {
        return R.ok(bpmManageApplication.getTaskListByProcessInstanceId(id));
    }
    
    @PostMapping("/assign-task")
    @ApiOperation(value = "转办任务")
    public R<?> assignTask(@RequestBody BpmManageReqVO reqVO) {
        bpmManageApplication.assignTask(reqVO);
        return R.ok();
    }
    
    @PostMapping("/jump-process")
    @ApiOperation(value = "节点跳转")
    public R<?> jumpProcess(@RequestBody BpmManageReqVO reqVO) {
        bpmManageApplication.jumpProcess(reqVO);
        return R.ok();
    }

    @PostMapping("/un-claim-task")
    @ApiOperation(value = "候选任务释放")
    public R<?> unClaimTask(@RequestBody BpmManageReqVO reqVO) {
        bpmManageApplication.unClaimTask(reqVO);
        return R.ok();
    }
    
    @PostMapping("/cancel-process")
    @ApiOperation(value = "流程终止")
    public R<?> cancelProcess(@RequestBody BpmManageReqVO reqVO) {
        bpmManageApplication.cancelInstance(reqVO);
        return R.ok();
    }
}
